package ThreadDemo.src;

/*
 * Author: JacksonCoder
 * FileName: ThreadExemple
 * Version: 1.0.0
 */
public class ThreadExemple {
    public static void main(String[] args) throws InterruptedException {
        AddThread addThread = new AddThread();
        DecThread decThread = new DecThread();
        addThread.start();
        decThread.start();
        addThread.join();
        decThread.join();
        System.out.println(Counter.count);

    }
}

class Counter{
    public static final Object lock = new Object();

    public static int count = 0;
}

class AddThread extends Thread{
    public void run(){
        for(int i = 0 ; i < 10000 ; i++){
            synchronized(Counter.lock){
                Counter.count++;
            }
        }
    }
}

class DecThread extends Thread{

    public void run(){
        for(int i = 0 ; i < 10000 ; i++){
            synchronized(Counter.lock){
                Counter.count--;
            }
        }
    }

}


